# @Version : 1.0
# @Author  : wxz
# @File    : docs_routers.py
# @Time    : 2025/5/30 10:04
# @Describe: 描述...
from typing import Annotated

from fastapi import APIRouter, Depends
from fastapi.security import OAuth2PasswordRequestForm
from sqlmodel import Session

from apps.docs_auth.exceptions.docs_exception import DocsTokenFromNotNullException
from apps.user.dao.user_dao import UserDAO
from apps.user.dao.user_ext_info_dao import UserExtInfoDAO
from apps.user.schemas.user_schema import UserLogin
from apps.user.service.user_service import UserService
from database.redis.redis_client import RedisClient, get_redis_client

docs = APIRouter()

@docs.post("/token", summary="API接口文档的Token认证")
async def docs_token(from_data: OAuth2PasswordRequestForm = Depends(), user_service: UserService = Depends()):
    """

    :param from_data:
    :return:
    """
    username = from_data.username
    password = from_data.password

    if not username or not password:
        raise DocsTokenFromNotNullException

    token = user_service.login(UserLogin(username=username, password=password))

    return {
        "token_type": "bearer",
        "access_token": token
    }













